package com.imooc.bilibili.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ConfirmConfig {
    // 声明交换机
    public static final String DANMU_EXCHANGE_NAME = "danmu.exchange";
    // 声明队列
    public static final String DANMU_QUEUE_NAME = "danmu.queue";
    // 声明routingKey
    public static final String DANMU_ROUTING_KEY = "danmu.key";


    @Bean
    public DirectExchange danmuExchange(){
        return new DirectExchange(DANMU_EXCHANGE_NAME);
    }

    @Bean
    public Queue danmuQueue(){
        return QueueBuilder.durable(DANMU_QUEUE_NAME).build();
    }

    @Bean
    public Binding danmuQueueBindingDanmuExchange(@Qualifier("danmuExchange") DirectExchange danmuExchange,
                                        @Qualifier("danmuQueue") Queue danmuQueue){
        return BindingBuilder.bind(danmuQueue).to(danmuExchange).with(DANMU_ROUTING_KEY);
    }

    // 声明交换机
    public static final String MOMENTS_EXCHANGE_NAME = "moments.exchange";
    // 声明队列
    public static final String MOMENTS_QUEUE_NAME = "moments.queue";
    // 声明routingKey
    public static final String MOMENTS_ROUTING_KEY = "moments.key";


    @Bean
    public DirectExchange momentsExchange(){
        return new DirectExchange(MOMENTS_EXCHANGE_NAME);
    }

    @Bean
    public Queue momentsQueue(){
        return QueueBuilder.durable(MOMENTS_QUEUE_NAME).build();
    }

    @Bean
    public Binding momentsQueueBindingMomentsExchange(@Qualifier("momentsExchange") DirectExchange momentsExchange,
                                        @Qualifier("momentsQueue") Queue momentsQueue){
        return BindingBuilder.bind(momentsQueue).to(momentsExchange).with(MOMENTS_ROUTING_KEY);
    }
}
